package com.example.xuanmei.video.controller;

import com.example.xuanmei.common.dto.ApiResponse;
import com.example.xuanmei.video.dto.VideoDto;
import com.example.xuanmei.video.dto.VideoUploadRequest;
import com.example.xuanmei.video.service.VideoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 视频控制器
 */
@RestController
@RequestMapping("/api/video")
@RequiredArgsConstructor
@CrossOrigin
public class VideoController {
    private final VideoService videoService;
    
    @PostMapping("/upload")
    public ApiResponse<VideoDto> uploadVideo(
            @RequestHeader("X-User-Id") Long userId,
            @RequestBody VideoUploadRequest request) {
        return videoService.uploadVideo(userId, request);
    }
    
    @GetMapping("/list")
    public ApiResponse<List<VideoDto>> getVideoList(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size) {
        return videoService.getVideoList(page, size);
    }
    
    @GetMapping("/user/{userId}")
    public ApiResponse<List<VideoDto>> getUserVideos(
            @PathVariable Long userId,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size) {
        return videoService.getUserVideos(userId, page, size);
    }
    
    @GetMapping("/{videoId}")
    public ApiResponse<VideoDto> getVideoDetail(@PathVariable Long videoId) {
        return videoService.getVideoDetail(videoId);
    }
    
    @PostMapping("/{videoId}/like")
    public ApiResponse<Void> likeVideo(@PathVariable Long videoId) {
        return videoService.likeVideo(videoId);
    }
}
